package com.lfsenior.redis;

import org.junit.Test;
import redis.clients.jedis.Jedis;

import java.util.*;

/**
 * Created by dlupan on 2018/10/10
 */
public class TestRedis {
    private static Jedis jedis=new Jedis("127.0.0.1",6379);
    @Test
    public void testConn(){
        Jedis jedis = new Jedis("127.0.0.1",6379);
        System.out.println("链接成功");
        System.out.println("服务器正在运行"+jedis.ping());
    }

    @Test
    public void strOption(){
        jedis.set("strOption", "字符串操作");
        System.out.println("服务器上的内容:"+jedis.get("strOption"));
    }


    @Test
    public void listOption(){
        jedis.lpush("listOption","集合操作1");
        jedis.lpush("listOption","集合操作2");
        jedis.lpush("listOption","集合操作3");
        List<String> listOption = jedis.lrange("listOption", 0, 2);
        System.out.println("服务器上的内容:"+ listOption.toString());
    }

    /*.....*/
    @Test
    public void hashOption(){
        Map<String,String> param=new HashMap<>();
        param.put("f1","Hash操作1");
        param.put("f2","Hash操作2");
        param.put("f3","Hash操作3");
        jedis.hmset("hashOption",param);
        System.out.println("服务器上的内容:"+jedis.hget("hashOption","f1")+","+jedis.hget("hashOption","f2")+","+jedis.hget("hashOption","f3"));
    }

    @Test
    public void keysOption(){
        Set<String> keys = jedis.keys("*");
        System.out.println("服务器上的内容:"+keys.toString());
    }
}
